package com.zzg.demo.springbatch.demo.customer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

/**
 * @Description :监听Job执行情况，实现JobExecutorListener，且在batch配置类里，Job的Bean上绑定该监听器
 **/
@Slf4j
public class MyJobListener implements JobExecutionListener {
    @Override
    public void beforeJob(JobExecution jobExecution) {
        log.info("MyCustomerJobListener-job 开始, id={}",jobExecution.getJobId());
        // 设置execution级别的上下文参数
        jobExecution.getExecutionContext().put("jobLevelParam", "beforeJob");
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        log.info("MyCustomerJobListener-job 结束, id={}",jobExecution.getJobId());
        log.info("afterJob readJobLevelParam:{}", jobExecution.getExecutionContext().get("jobLevelParam"));
        // 设置execution级别的上下文参数
        jobExecution.getExecutionContext().put("jobLevelParam", "afterJob");
    }
}
